<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!doctype html>
<html>
<head>
    <%@ include file="/common.jsp" %>
    <title>入驻申请 法人信息</title>
    <link rel="stylesheet" type="text/css" href="${ctx }/css/weui.min.css"/>
    <link rel="stylesheet" type="text/css" href="${ctx}/statics/aui/css/aui.css"/>
</head>
<body>
<section class="aui-content">
    <img src="${ctx}/statics/aui/images/regLogo.png" style="width: 100%;">
</section>

<div class="page">
    <div class="page__bd" style="height: 100%;">
        <div class="weui-tab">
            <div class="weui-navbar">
                <div class="weui-navbar__item" id="isApplyDiv1">
                    第一步
                </div>
                <div class="weui-navbar__item weui-bar__item_on" id="isApplyDiv2">
                    第二步
                </div>
                <div class="weui-navbar__item" id="isApplyDiv3">
                    第三步
                </div>
            </div>
            <div class="weui-tab__panel">

                <form action="${ctx}/auth/submitLegalPerson" method="post" id="submitLegalPerson"
                      enctype="multipart/form-data">

                    <!-- 第二步操作   -->
                    <div class="page__bd isApplyDiv" id="isApply2">
                        <input type="hidden" id="applyStart" name="applyStart" value="${applyStart}">
                        <div class="weui-cells__title"><h4 class="page__title">企业法人信息</h4></div>
                        <div class="weui-cells weui-cells_form">
                            <div class="weui-cell" id="legalNameDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__hd"><label class="weui-label">法人姓名</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" id="legalName" name="legalName" maxlength="10" value="${merchantInfo.legalName}"
                                           type="text"
                                           placeholder="法人姓名">
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                            <div class="weui-cell" id="idCardDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__hd"><label class="weui-label">法人身份证号码</label></div>
                                <div class="weui-cell__bd">
                                    <input class="weui-input" id="idCard" name="idCard" maxlength="18" value="${merchantInfo.idCard}"
                                           type="text" placeholder="法人身份证号码">
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                        </div>
                        <div class="weui-cells__title"><h4 class="page__title">法人身份证原件照</h4></div>
                        <div class="weui-cells weui-cells_form">
                            <div class="weui-cell" id="positiveDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__bd">
                                    <img v-model="positiveImg" id="pImg" src="${ctx}/lookImage?filePath=${merchantInfo.positiveImg}&imgSize=400x100" onerror="javascript:this.src='${ctx}/statics/aui/images/sfzzm.png'"
                                         alt="上传身份证正面照" width="90%" height="100px;" onclick="positive.click()">
                                    <input type="file" name="positive" id="positive"
                                           style="visibility: hidden; height: 0px;"
                                           multiple accept="image/*" capture="camera"
                                           onchange="readURL('pImg',this)">
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                            <%--https://weui.io/#uploader--%>
                            <div class="weui-cell" id="oppositeDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__bd">
                                    <img v-model="oppositeImg" id="oppositeImg" title="上传身份证反面照"
                                         src="${ctx}/lookImage?filePath=${merchantInfo.oppositeImg}&imgSize=400x100" onerror="javascript:this.src='${ctx}/statics/aui/images/sfzfm.png'"
                                         width="90%"
                                         height="100px" onclick="opposite.click()">
                                    <input type="file" id="opposite" name="opposite"
                                           style="visibility: hidden; height: 0px"
                                           multiple
                                           capture="camera" accept="image/*" onchange="readURL('oppositeImg',this)">
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                        </div>
                        <div class="weui-cells__title"><h4 class="page__title">营业执照</h4></div>
                        <div class="weui-cells weui-cells_form">
                            <div class="weui-cell" id="businessLicenseDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__bd">
                                    <img v-model="businessLicenseImg" id="businessLicenseImg" title="上传营业执照"
                                         src="${ctx}/lookImage?filePath=${merchantInfo.businessLicenseImg}&imgSize=400x100" onerror="javascript:this.src='${ctx}/statics/aui/images/dpns.png'"
                                         width="90%" height="100px;" onclick="businessLicense.click()">
                                    <input type="file" name="businessLicense" id="businessLicense"
                                           style="visibility: hidden; height: 0px;"
                                           multiple accept="image/*" capture="camera"
                                           onchange="readURL('businessLicenseImg',this)">
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                        </div>
                        <div class="weui-cells__title"><h4 class="page__title">银行开户许可证</h4></div>
                        <div class="weui-cells weui-cells_form">
                            <div class="weui-cell" id="bankLicenseDiv"><!-- weui-cell_warn -->
                                <div class="weui-cell__bd">
                                    <img v-model="bankLicenseImg" id="bankLicenseImg"
                                         src="${ctx}/lookImage?filePath=${merchantInfo.bankLicenseImg}&imgSize=400x100" onerror="javascript:this.src='${ctx}/statics/aui/images/dpns.png'"
                                         width="90%" height="100px" onclick="bankLicense.click()">
                                    <input type="file" id="bankLicense" name="bankLicense"
                                           style="visibility: hidden; height: 0px"
                                           multiple
                                           capture="camera" accept="image/*" onchange="readURL('bankLicenseImg',this)">
                                </div>
                                <div class="weui-cell__ft">
                                    <i class="weui-icon-warn"></i>
                                </div>
                            </div>
                        </div>
                        <div class="page__bd page__bd_spacing">
                            <div class="weui-cell"><!-- weui-cell_warn -->
                                <br/>
                                <div style="width: 40%;padding-right: 10px">
                                    <input type="button" id="submitUpStep" class="weui-btn weui-btn_primary"
                                           onclick="onclkAppUpStep(1);"
                                           value="上一步">
                                </div>
                                <div style="width: 55%">
                                    <input type="button" id="subButtonCompany" class="weui-btn weui-btn_primary"
                                           onclick="onclkAppLegalPerson();"
                                           value="下一步">
                                </div>
                            </div>
                            <br/>
                        </div>
                    </div>

                </form>


            </div>
        </div>
    </div>
</div>

<div id="dialogs">
    <div class="js_dialog" id="iosDialog2" style="display: none;">
        <div class="weui-mask"></div>
        <div class="weui-dialog">
            <div class="weui-dialog__bd" id="DialogMessage"></div>
            <div class="weui-dialog__ft">
                <a href="javascript:;" class="weui-dialog__btn weui-dialog__btn_primary DeleteDefault">确定</a>
            </div>
        </div>
    </div>
    <!-- loading toast -->
    <div id="loadingToast" style="display:none;">
        <div class="weui-mask_transparent"></div>
        <div class="weui-toast">
            <i class="weui-loading weui-icon_toast"></i>
            <p class="weui-toast__content">数据处理中</p>
        </div>
    </div>
</div>

<script type="text/javascript">

	var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",
			21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",
			33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",
			41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",
			46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",
			54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",
			65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外"};
		
    //弹框提示初始化
    var $iosDialog2 = $('#iosDialog2');
    $('#dialogs').on('click', '.DeleteDefault', function () { //取消按钮事件
        $(this).parents('.js_dialog').fadeOut(200);
    });
    //上传图片选取展现
    function readURL(outerImg, input) {
        if (input.files && input.files[0]) {
            var reader = new FileReader();
            reader.onload = function (e) {
                document.getElementById(outerImg).src = e.target.result;
            }
            reader.readAsDataURL(input.files[0]);
        }
    }

    //光标离开事件
    $(".weui-input").blur(function(){
        var divname=this.name+"Div";
        if ($(this).val().trim().length == 0) {
            $('#'+divname).addClass("weui-cell_warn");
        }else{
            $('#'+divname).removeClass("weui-cell_warn");
        }
       
        if(divname=="idCardDiv"){
        	var iSum=0 ;
        	var idCard = $(this).val();
        	idCard = idCard.replace(/x$/i,"a"); 
        	sBirthday = idCard.substr(6,4)+"-"+Number(idCard.substr(10,2))+"-"+Number(idCard.substr(12,2)); 
        	var d=new Date(sBirthday.replace(/-/g,"/")) ;
        	for(var i = 17;i>=0;i --){
 		    	iSum += (Math.pow(2,i) % 11) * parseInt(idCard.charAt(17 - i),11) ;
 		    }
        	
        	if($(this).val().length != 18 && !/^\d{17}(\d|x)$/i.test(idCard)){
        		$('#'+divname).addClass("weui-cell_warn");
        		$("#DialogMessage").html("输入的身份证长度错误");
                $iosDialog2.fadeIn(200);
        	}else if(aCity[parseInt($(this).val().replace(/x$/i,"a").substr(0,2))]==null){
 		    	$('#'+divname).addClass("weui-cell_warn");
        		$("#DialogMessage").html("输入的身份证格式错误");
                $iosDialog2.fadeIn(200);
        	}else if(sBirthday != (d.getFullYear()+"-"+ (d.getMonth()+1) + "-" + d.getDate())){
 		    	$('#'+divname).addClass("weui-cell_warn");
 		    	$("#DialogMessage").html("输入的身份证格式错误");
        		//$("#DialogMessage").html("身份证上的出生日期非法");
                $iosDialog2.fadeIn(200);
 		    }
        	/* else if(iSum%11!=1){
 		    	$('#'+divname).addClass("weui-cell_warn");
        		$("#DialogMessage").html("输入的身份证号非法");
                $iosDialog2.fadeIn(200);
 		    } */
        }
    });
    ///商户入驻 数据验证
    function valdateAppLegalPerson(objName) {
        $('#legalNameDiv').removeClass("weui-cell_warn");
        $('#idCardDiv').removeClass("weui-cell_warn");
        $('#positiveDiv').removeClass("weui-cell_warn");
        $('#oppositeDiv').removeClass("weui-cell_warn");
        $('#businessLicenseDiv').removeClass("weui-cell_warn");
        $('#bankLicenseDiv').removeClass("weui-cell_warn");
        $('#applyStartDiv').removeClass("weui-cell_warn");

        var legalName = $("#legalName").val();
        var idCard = $("#idCard").val();//法人身份证号码
        var positive = $("#positive").val();//上传身份证正面照
        var opposite = $("#opposite").val();//上传身份证反面照
        var businessLicense = $("#businessLicense").val();//营业执照
        var bankLicense = $("#bankLicense").val();//银行开户许可证
        var applyStart = $("#applyStart").val();//判断是否为上一步操作进入页

        var errorMessage = "";
        if ((objName=="legalName"||objName=="objName")&&legalName.trim().length == 0) {
            errorMessage = "请填写法人姓名";
            $('#legalNameDiv').addClass("weui-cell_warn");
        }if ((objName=="idCard"||objName=="objName")&&idCard.trim().length == 0) {
            errorMessage = "请填写法人身份证号码";
            $('#idCardDiv').addClass("weui-cell_warn");
        }
        if(applyStart.trim().length==0){
            if ((objName=="positive"||objName=="objName")&&positive.trim().length == 0) {
                errorMessage = "请上传法人身份证正面照";
                $('#positiveDiv').addClass("weui-cell_warn");
            } if ((objName=="opposite"||objName=="objName")&&opposite.trim().length == 0) {
                errorMessage = "请上传法人身份证反面照";
                $('#oppositeDiv').addClass("weui-cell_warn");
            } if ((objName=="businessLicense"||objName=="objName")&&businessLicense.trim().length == 0) {
                errorMessage = "请上传营业执照";
                $('#businessLicenseDiv').addClass("weui-cell_warn");
            } if ((objName=="bankLicense"||objName=="objName")&&bankLicense.trim().length == 0) {
                errorMessage = "请上传银行开户许可证";
                $('#bankLicenseDiv').addClass("weui-cell_warn");
            }
        }
        if (errorMessage != "") {
            $('#loadingToast').fadeOut(100);
            $("#DialogMessage").html("您有没填完的信息，请填写");
            $iosDialog2.fadeIn(200);
            return true;
        } else {
            return false;
        }
    }

    ///商户入驻 第二步 数据保存
    function onclkAppLegalPerson() {
        $('#loadingToast').fadeIn(100);
        if (valdateAppLegalPerson("objName")) {
            return;
        } else {
            $("#submitLegalPerson").submit();
        }
    }

    //上一步处理
    function onclkAppUpStep(numb) {
        window.location.href = "${ctx}/auth/submitUpStep?presentNub=" + numb;
    }
</script>
</body>
